package h0717;

import java.util.Scanner;
/**
  * @description 三叉树的高度
  * @author 不知名帅哥
  * @date 2024/7/17 23:32
  * @version 1.0
*/
public class ThreeSearchTreeHeight {
    static class TreeNode{
        int val;
        int height;  //节点所在高度
        TreeNode left;  //左子树
        TreeNode mid;  //中子树
        TreeNode right; //右子树
        public TreeNode(int val){
            this.val=val;
        }
    }
    static class Tree{
        int height;
        TreeNode root; //树的根节点

        public void add(int val){
            TreeNode node=new TreeNode(val);
            if (this.root==null){
                node.height=1;
                this.root=node;
                this.height=1;
            }else {
                TreeNode cur=this.root;
                while (true){
                    //假设创建的节点node是当前节点cur的子节点，则node节点高度值=cur节点高度值+1；
                    node.height= cur.height+1;
                    //如果创建的node进入新层，则更新树的高度
                    this.height=Math.max(node.height,this.height);

                    if (val< cur.val-500){
                        if (cur.left==null){
                            cur.left=node;
                            break;
                        }else {
                            cur=cur.left;
                        }
                    }else if (val> cur.val+500){
                        if (cur.right==null){
                            cur.right=node;
                            break;
                        }else {
                            cur=cur.right;
                        }
                    }else {
                        if(cur.mid==null){
                            cur.mid=node;
                            break;
                        }else {
                            cur=cur.mid;
                        }
                    }
                }
            }
        }

    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        Tree tree = new Tree();
        for (int i = 0; i < n; i++) {
            tree.add(sc.nextInt());
        }
        System.out.println(tree.height);
    }
}
